window.addEventListener('load', function() {
	var side = document.querySelector('.side');
	var focue = document.querySelector('.focue');
	var last = document.querySelector('.last');
	var focueTop = focue.offsetTop;
	var sideTop = side.offsetTop - focueTop;
	console.log(sideTop);
	console.log(focueTop);
	document.addEventListener('scroll', function() {
		// console.log(focue.pageYOffset - side.offsetTop);
		if(window.pageYOffset >= focueTop) {
			last.style.display = 'block';
			side.style.position = 'fixed';
			side.style.top = sideTop + 'px';
		} else {
			last.style.display = 'none';
			side.style.position = 'absolute';
			side.style.top = focueTop + sideTop + 'px';
			
		}
	})
	// 2.点击顶部返回顶部
	last.addEventListener('click', function() {
		// window.scroll(0,0);
		anmite(window, 0)
	})
	function anmite(obj, target, callback) {
		clearInterval(obj.time);
		obj.time = setInterval(function(){
			var step = (target - window.pageYOffset) / 10;
			var step = step > 0 ? Math.ceil(step) : Math.floor(step);
			if(window.pageYOffset == target) {
				clearInterval(obj.time);
				callback && callback();
			}		
			window.scroll(0, window.pageYOffset + step);
		},15)
	}
})